package com.zpark.se.io.writer;

import java.io.*;

/**
 * 字符输出流转换流
 * OutputStreamWriter：字节输出流到字符输出流，可以指定编码
 */
public class Demo04 {
    public static void main(String[] args) throws Exception {
        /*// 创建File文件对象
        File file = new File("src/com/zpark/se/io/writer/a/c.txt");
        // 创建文件按字节输出流对象
        FileOutputStream fos = new FileOutputStream(file);
        // 创建字节缓冲输出流对象
        BufferedOutputStream bos = new BufferedOutputStream(fos);

        // 创建转换流对象
        OutputStreamWriter osw = new OutputStreamWriter(bos, "gbk");

        // 创建字符输出流缓冲区
        BufferedWriter bw = new BufferedWriter(osw);*/

        BufferedWriter bw = new BufferedWriter(
                new OutputStreamWriter(
                        new BufferedOutputStream(
                                new FileOutputStream(
                                        new File("src/com/zpark/se/io/writer/a/c.txt")
                                )
                        ), "gbk")
        );

        bw.write("《过零丁洋》宋朝·文天祥");
        bw.newLine();
        bw.write("辛苦遭逢起一经，干戈寥落四周星。");
        bw.newLine();
        bw.write("山河破碎风飘絮，身世浮沉雨打萍。");
        bw.newLine();
        bw.write("惶恐滩头说惶恐，零丁洋里叹零丁。");
        bw.newLine();
        bw.write("人生自古谁无死？留取丹心照汗青。 ");

        // 关闭流
        bw.close();
    }
}
